<?php
	function doPostRequest($url, $data, $optional_headers = null) {
		$params = array('http' => array('method' => 'POST', 'content' => $data)); 
		if ($optional_headers !== null) {
			$params['http']['header'] = $optional_headers;
		}
		$ctx = stream_context_create($params);
		$fp = @fopen($url, 'rb', false, $ctx); 
		if (!$fp) { 
			throw new Exception("Problem with $url, $php_errormsg");
		}
		$response = @stream_get_contents($fp); 
		if ($response === false) { 
			throw new Exception("Problem reading data from $url, $php_errormsg");
		}
		return $response;
	}
	
	function getUserIp() { 
		if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
			$TheIp=$_SERVER['HTTP_X_FORWARDED_FOR'];
		else $TheIp=$_SERVER['REMOTE_ADDR'];
		return trim($TheIp);
    }
	

	$stringData = $_POST["data"];
	$userIp = getUserIp();
	$stringData = str_replace("</login>", "<ip>"+$userIp+"</ip>", $stringData);
	$stringData .= "</login>";
	$response = doPostRequest("http://localhost:9000/", $stringData);
	echo $response;
?>
